<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <span>
          <b class="u-f-16">订单列表</b>
        </span>
      </div>

      <el-form :inline="true" :model="queryForm" size="small" class="u-text-center">
        <el-form-item label="是否拼团：" style="display: none">
          <el-checkbox-group v-model="queryForm.order_pt">
            <el-checkbox label="拼团" name="order_pt"></el-checkbox>
            <el-checkbox label="不拼团" name="order_pt"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="下单时间">
          <el-date-picker v-model="queryForm.time_section" type="daterange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期" format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item label="订单关键字">
          <el-input v-model="queryForm.keyword" placeholder="订单关键字" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="searchOrder">查询</el-button>
          <el-button type="success" icon="el-icon-s-order" @click="onExportOrder" v-if="hasPerm('orderExportGet')">导出
          </el-button>
        </el-form-item>
        <el-row>
          <el-button :type="buttonType == 2 ? 'success' : ''" @click="changeStatus(2)">待发货</el-button>
          <el-button :type="buttonType == 1 ? 'success' : ''" @click="changeStatus(1)">待付款</el-button>
          <el-button :type="buttonType == 3 ? 'success' : ''" @click="changeStatus(3)">已发货</el-button>
          <el-button :type="buttonType == 4 ? 'success' : ''" @click="changeStatus(4)">已收货</el-button>
          <el-button :type="buttonType == 5 ? 'success' : ''" @click="changeStatus(5)">已完成</el-button>
          <el-button :type="buttonType == 6 ? 'success' : ''" @click="changeStatus(6)">已取消</el-button>
          <el-button :type="buttonType == 0 ? 'success' : ''" @click="changeStatus(0)">全部订单</el-button>
        </el-row>
      </el-form>

      <el-table :data="tableData" class="u-mt-10" v-viewer>
        <el-table-column label="id" prop="id" width="60"></el-table-column>
        <el-table-column label="用户信息" width="120">
          <template slot-scope="scope">
            <div class="head-img">
              <el-image class="el-img" :src="scope.row.head_img" fit="cover" lazy></el-image>
            </div>
            <div class="nick_name">{{ scope.row.nick_name }}</div>
          </template>
        </el-table-column>
        <el-table-column label="地址信息" width="260">
          <template slot-scope="scope">
            <p>{{ scope.row.take_name }}</p>
            <p>{{ scope.row.take_phone }}</p>
            <p>{{ scope.row.take_address }}</p>
            <p>
              <el-button size="mini" @click="onCopyAdd(scope.row)">复制</el-button>
              <el-button type="danger" size="mini" @click="openOrderAddress(scope.row)"
                v-if="scope.row.order_status > 0 && scope.row.order_status <= 3">修改</el-button>
            </p>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" width="80">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_status == 0" type="info">已取消</el-tag>
            <el-tag v-if="scope.row.order_status == 1" type="info">待付款</el-tag>
            <el-tag v-if="scope.row.order_status == 2" type="success">已付款</el-tag>
            <el-tag v-if="scope.row.order_status == 3">已发货</el-tag>
            <el-tag v-if="scope.row.order_status == 4" type="warning">已收货</el-tag>
            <el-tag v-if="scope.row.order_status == 5" type="danger">已完成</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="群主所属" width="110">
          <template slot-scope="scope">
            <el-tag type="info">{{
            scope.row.agency_title == "" ? "无" : scope.row.agency_title
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="商品详情">
          <template slot-scope="scope">
            <div v-for="(goods_item, index) in scope.row.order_detail" class="goods_title_p"
              :class="index % 2 == 0 ? 'info' : 'text'" :key="goods_item.id">
              <div class="goods-items">
                <div class="goods-title">
                  <span>名称：</span>
                  {{ goods_item.goods_title }}
                </div>
                <div>
                  <span>规格：</span>
                  {{ goods_item.attribute_names }}
                </div>
              </div>
              <div class="goods-number" style="font-weight: 700" :style="
                goods_item.goods_number > 1 ? 'color: #409EFF' : 'color: red'
              " v-if="buttonType != 2 && buttonType != 7">
                {{ goods_item.goods_number }}(件)
              </div>
              <div class="goods-number" style="font-weight: 700" :style="
                goods_item.goods_number > 1 ? 'color: #409EFF' : 'color: red'
              " v-if="buttonType == 2">
                {{ goods_item.goods_number - goods_item.send_number }}(件)
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="订单详情">
          <template slot-scope="scope">
            <div class="order-price info">
              <div class="label">实际收款总额：</div>
              <div class="price" style="color: #f56c6c">
                ￥{{ scope.row.actual_price }}
              </div>
            </div>
            <div class="order-price text">
              <div class="label">实际成本价：</div>
              <div class="price">￥{{ scope.row.total_cost_price }}</div>
            </div>
            <div class="order-price text">
              <div class="label">总利润：</div>
              <div class="price">￥{{ scope.row.total_profit }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="120">
          <template slot-scope="scope">
            <el-button type="success" size="small" @click="setParastatus(scope.row.id, scope.row)"
              v-if="scope.row.order_status == 1">确认收款</el-button>
            <el-button type="danger" size="small" @click="openOrderPrice(scope.row)" v-if="scope.row.order_status == 1">
              修改金额</el-button>
            <el-button type="danger" size="small" @click="openOrderCostPrice(scope.row)">修改成本价</el-button>
            <el-button type="danger" size="small" @click="setLogistics(scope.row.id)"
              v-if="scope.row.order_status == 2">一键发货</el-button>
            <el-button type="danger" size="small" @click="confirmTake(scope.row.id)" v-if="scope.row.order_status == 3">
              确认收货</el-button>
            <el-button type="danger" size="small" @click.native="handleRoute(scope.row.id, 'orderOutEdit')"
              v-if="scope.row.out_handle_status == 1">退款处理</el-button>
            <el-button type="warning" size="small" @click.native="handleRoute(scope.row.id, 'orderDetail')"
              v-if="hasPerm('orderDetail')">查看详情</el-button>
            <el-button type="info" size="small" @click="showLogistics(scope.row.id)" v-if="scope.row.order_status == 3">
              查看物流</el-button>
            <el-button type="info" size="small" @click="openSetLogistics(scope.row)" v-if="scope.row.order_status >= 3">
              修改物流</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog title="收款金额" :visible.sync="parastatus" width="400px">
        <el-form :model="objForm" label-width="80px">
          <el-form-item label="收款金额">
            <el-input v-model="actual_price" type="text" placeholder="请输入收款金额">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="parastatus = false">取 消</el-button>
          <el-button type="primary" @click="submitPara()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="物流信息" :visible.sync="is_logistics_log_show" width="800px">
        <Logistics :list="logistics_log.list" :traces="logistics_log.traces" @tabchange="getLogisticsTraces">
        </Logistics>
        <div slot="footer" class="dialog-footer">
          <el-button @click="is_logistics_log_show = false">关 闭</el-button>
        </div>
      </el-dialog>
      <el-dialog title="填写物流信息" :visible.sync="is_logistics_show" width="900px">
        <el-row>
          <el-button :type="is_logType_show ? 'success' : ''" @click="logType(1)">物流</el-button>
          <el-button :type="is_logType_show ? '' : 'success'" @click="logType(2)">自提</el-button>
        </el-row>
        <el-form :model="objForm" label-width="80px">
          <el-table :data="goodsData" @selection-change="handleSelectionChange" class="u-mt-10" v-viewer>
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column label="id" prop="id" width="50"></el-table-column>
            <el-table-column label="图片" width="100">
              <template slot-scope="scope">
                <el-image style="max-width: 50px" :src="scope.row.goods_img" :data-src="scope.row.goods_img" fit="cover"
                  lazy></el-image>
              </template>
            </el-table-column>
            <el-table-column label="标题" prop="goods_title"></el-table-column>
            <el-table-column label="规格" prop="attribute_names"></el-table-column>
            <el-table-column label="中数量" width="70" prop="goods_number"></el-table-column>
            <el-table-column label="已发货" width="70" prop="send_number"></el-table-column>
            <el-table-column label="未发货" width="70" prop="need_number"></el-table-column>
            <el-table-column label="发货数" width="150">
              <template slot-scope="scope">
                <el-input-number size="mini" v-model="scope.row.now_send_number" :max="scope.row.need_number" />
              </template>
            </el-table-column>
          </el-table>
          <div v-if="is_logType_show == true">
            <el-row>
              <el-col :span="12">
                <el-form-item label="快递名称" style="margin-top: 15px">
                  <el-select v-model="code" placeholder="请选择快递名称">
                    <el-option label="请选择" value="0"></el-option>
                    <el-option v-for="item in logistics" :key="item.id" :label="item.logistics_name"
                      :value="item.logistics_code"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="运单号" style="margin-top: 15px">
                  <el-input v-model="number" type="text" placeholder="请输入运单号"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-form-item label="备注信息" v-if="false">
            <el-input type="textarea" v-model="remark"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="is_logistics_show = false">取 消</el-button>
          <el-button type="primary" @click="submitLogistics()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="修改收货地址" :visible.sync="is_set_address_show" width="600px">
        <el-form :model="addressData" label-width="80px">
          <el-form-item label="收货人">
            <el-input v-model="addressData.name" type="text" placeholder="请输入收货人"></el-input>
          </el-form-item>
          <el-form-item label="收货电话">
            <el-input v-model="addressData.phone" type="text" placeholder="请输入收货电话"></el-input>
          </el-form-item>
          <el-form-item label="收货地址">
            <el-input v-model="addressData.address" type="text" placeholder="请输入收货地址"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="is_set_address_show = false">取 消</el-button>
          <el-button type="primary" @click="submitAddress()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="修改订单总价" :visible.sync="is_set_price_show" width="900px">
        <el-table :data="orderPrice.order_detail" stripe style="width: 100%">
          <el-table-column prop="goods_title" label="商品名称" width="280"></el-table-column>
          <el-table-column prop="attribute_names" label="商品规格" width="260"></el-table-column>
          <el-table-column prop="goods_number" label="数量"></el-table-column>
          <el-table-column prop="platform_price" label="单价"></el-table-column>
          <el-table-column prop="cost_price" label="总价"></el-table-column>
        </el-table>
        <el-form :model="orderPrice" label-width="100px">
          <el-row>
            <el-col :span="12">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="订单成本价">
                    <div>{{ orderPrice.old.cost }}元</div>
                  </el-form-item>
                  <el-form-item label="运费">
                    <div>{{ orderPrice.old.freight }}元</div>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="订单售价">
                    <div>
                      {{
                      orderPrice.old.order_total + orderPrice.old.difference
                      }}元
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="12">
              <el-form-item label="修改售价" style="margin-top: 15px">
                <el-input v-model="orderPrice.order_total" type="text" placeholder="请输入实际售价" @input="inputOrderTotal">
                  <template slot="append">差价：{{
                  orderPrice.order_total - orderPrice.old.order_total
                  }}元</template>
                </el-input>
              </el-form-item>
              <el-form-item label="修改运费">
                <el-input v-model="orderPrice.freight" @input="inputOrderFreight" type="text" placeholder="请输入实际运费">
                  <template slot="append">差价：{{
                  orderPrice.freight - orderPrice.old.freight
                  }}元</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-form :model="orderPrice" label-width="150px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="订单成本价(含有运费)">
                <el-input v-model="orderPrice.cost" @input="inputOrderCost" type="text" placeholder="请输入实际成本价">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="修改前订单总价">
                <div>
                  {{ orderPrice.old.order_total + orderPrice.old.freight }}元
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="修改购订单总价">
                <div>
                  {{
                  parseFloat(orderPrice.order_total) +
                  parseFloat(orderPrice.freight)
                  }}元
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="is_set_price_show = false">取 消</el-button>
          <el-button type="primary" @click="submitPrice()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="订单成本价" :visible.sync="is_set_cost_price_show" width="400px">
        <el-form :model="objForm" label-width="180px">
          <el-form-item label="订单运费">
            <div>{{ subOrderPrice.freight }}元</div>
          </el-form-item>
          <el-form-item label="订单成本价(不含有运费)">
            <el-input v-model="subOrderPrice.cost" type="text" placeholder="请输入订单成本价">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="is_set_cost_price_show = false">取 消</el-button>
          <el-button type="primary" @click="submitCostPrice()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="修改运单号" :visible.sync="is_set_logistics_show" width="700px">
        <el-form label-width="100px">
          <div class="logistics-item" v-for="(item, index) in logisticsNumbers" v-bind:key="index">
            <el-card class="box-card">
              <div class="logistics-goods-list" v-for="(itemx, indexx) in item.order_item_info" v-bind:key="indexx">
                <el-row>
                  <el-col :span="4">
                    <el-image style="max-width: 70px" :src="itemx.goods_img" :data-src="itemx.goods_img" fit="cover"
                      lazy></el-image>
                  </el-col>
                  <el-col :span="20">
                    <div class="logistics-goods-title">
                      名称：{{ itemx.goods_title }}
                    </div>
                    <div class="logistics-goods-names">
                      规格：{{ itemx.attribute_names }}
                    </div>
                    <div class="logistics-goods-number">
                      数量：{{ itemx.now_send_number }}
                    </div>
                  </el-col>
                </el-row>

                <div class="line"></div>
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="快递名称" style="margin-top: 15px">
                    <el-select v-model="logisticsNumbers[index].logistics_code" placeholder="请选择快递名称">
                      <el-option label="请选择" value="0"></el-option>
                      <el-option v-for="item in logistics" :key="item.id" :label="item.logistics_name"
                        :value="item.logistics_code"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="运单号" style="margin-top: 15px">
                    <el-input v-model="logisticsNumbers[index].logistics_number" type="text" placeholder="请输入运单号">
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <div class="line"></div>
            </el-card>
          </div>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="is_set_logistics_show = false">取 消</el-button>
          <el-button type="primary" @click="submitSetLogistics()">确 定</el-button>
        </div>
      </el-dialog>
      <div class="u-mt-20 u-text-center">
        <el-pagination background @size-change="handleSizeChange" @current-change="handlePageChange"
          :current-page="currentPage" :page-sizes="[10, 20, 30, 40, 50]" :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonPage from "@/mixins/common-page";
import Logistics from "@/components/logistics/logistics";
import store from "@/store";
import { getApiUrl } from "@/libs/util";
export default {
  components: {
    Logistics,
  },
  mixins: [commonPage],
  data() {
    return {
      apiName: "order",
      queryForm: {
        time_section: "", //下单时间区间
        order_pt: [], //是否是拼团订单
        status: "",
        keyword: "",
      },
      buttonType: 2,
      objForm: {
        id: "",
      },
      addressData: {
        //修改收货地址
        id: "",
        phone: "",
        name: "",
        address: "",
      },
      orderPrice: {
        old: {
          freight: 0, //运费
          order_total: 0, //老售价价
          cost: 0, //实际成本
          difference: 0, //补差价
        },
        cost_price: 0,
        order_total: 0, //新售价
        freight: 0, //运费
        difference: 0, //补差价
        cost: 0, //实际成本
      }, //修改金额
      subOrderPrice: {
        freight: 0, //运费
        difference: 0, //补差价
        cost: 0, //实际成本
      },
      goodsData: [],
      logistics: [],
      logistics_log: {},
      is_logistics_show: false,
      is_logistics_log_show: false, //发货管理
      is_set_logistics_show: false, //修改运单号
      is_set_price_show: false, //修改运单
      is_set_address_show: false, //修改收货地址
      is_set_cost_price_show: false, //修改订单成本价
      send_type: "0",
      item_id: [],
      item_number: [],
      code: "",
      number: "",
      remark: "",
      parastatus: false, // 收款弹框
      actual_price: 0.0, // 实际收款金额
      logisticsNumbers: [], //快递单号
      order_id: "",
      is_logType_show: true,
    };
  },
  methods: {
    onExportOrder() {
      let start = "";
      let end = "";
      if (this.queryForm.time_section) {
        start = Date.parse(this.queryForm.time_section[0]);
        end = Date.parse(this.queryForm.time_section[1]);
      }
      let url =
        getApiUrl() +
        "/order/exportOrder?type=AppAdmin&token=" +
        store.getters.access_token +
        "&start=" +
        start +
        "&end=" +
        end + 
        "&order_status=" + 
        this.queryForm.status;
      // console.log(url);
      window.open(url);
    },
    inputOrderTotal(e) {
      this.subOrderPrice.difference =
        parseFloat(e) - parseFloat(this.orderPrice.old.order_total);
      console.log(this.orderPrice);
      console.log(this.subOrderPrice);
    },
    inputOrderFreight(e) {
      this.subOrderPrice.freight = parseFloat(e);
      this.orderPrice.cost =
        parseFloat(this.orderPrice.cost_price) + parseFloat(e);
    },
    inputOrderCost(e) {
      this.subOrderPrice.cost =
        parseFloat(e) - parseFloat(this.subOrderPrice.freight);
    },
    //复制地址
    onCopyAdd(item) {
      let addr =
        item.take_name + "\n" + item.take_phone + "\n" + item.take_address;
      this._copy(addr);
    },
    _copy(data) {
      let url = data;
      let oInput = document.createElement("textarea");
      oInput.value = url;
      document.body.appendChild(oInput);
      oInput.select(); // 选择对象;
      document.execCommand("Copy"); // 执行浏览器复制命令
      this.$message({
        message: "复制成功",
        type: "success",
      });
      oInput.remove();
    },
    openOrderAddress(item) {
      //修改收货地址
      this.is_set_address_show = true;
      this.addressData.id = item.id;
      this.addressData.phone = item.take_phone;
      this.addressData.name = item.take_name;
      this.addressData.address = item.take_address;
    },
    submitAddress() {
      this.is_set_address_show = false;
      let self = this;
      self.$api[self.apiName].setAddress(self.addressData).then((response) => {
        if (response.code == 1) {
          self.onLoad();
        }
      });
    },
    openSetLogistics(item) {
      this.is_set_logistics_show = true;
      this.order_id = item.id;
      this.logisticsNumbers = item.logistics_numbers;
    },
    submitSetLogistics() {
      this.is_set_logistics_show = false;
      let self = this;
      let numbers = [];
      this.logisticsNumbers.forEach((item) => {
        numbers.push({
          id: item.id,
          logistics_number: item.logistics_number,
          logistics_code: item.logistics_code,
        });
      });
      let json = {
        id: this.order_id,
        numbers: numbers,
      };
      self.$api[self.apiName].setLogisticsNumber(json).then((response) => {
        if (response.code == 1) {
          self.onLoad();
        }
      });
    },
    openOrderCostPrice(item) {
      //修改订单金额
      this.is_set_cost_price_show = true;
      this.subOrderPrice.freight = item.freight_price; //运费
      this.subOrderPrice.cost = item.cost_price;
      this.order_id = item.id;
    },
    submitCostPrice() {
      this.is_set_cost_price_show = false;
      let self = this;

      let json = {
        id: this.order_id,
        price: this.subOrderPrice,
      };
      self.$api[self.apiName].setOrderPrice(json).then((response) => {
        if (response.code == 1) {
          self.onLoad();
        }
      });
    },
    openOrderPrice(item) {
      //修改订单金额
      this.is_set_price_show = true;
      this.orderPrice.order_detail = item.order_detail; //商品详情
      this.orderPrice.old.freight = parseFloat(item.freight_price); //老-运费
      this.orderPrice.old.order_total = parseFloat(item.order_total); //老-应付价格
      this.orderPrice.old.cost = parseFloat(item.cost_price); //老-成本价
      this.orderPrice.old.difference = parseFloat(item.difference_price); //老-差价
      this.orderPrice.order_total =
        parseFloat(item.order_total) + parseFloat(item.difference_price); //应付价格
      this.orderPrice.freight = parseFloat(item.freight_price); //运费
      this.orderPrice.difference = parseFloat(item.difference_price); //补差价
      this.orderPrice.cost =
        parseFloat(item.cost_price) + parseFloat(item.freight_price); //实际成本
      this.orderPrice.cost_price = parseFloat(item.cost_price);
      this.order_id = item.id;
      this.subOrderPrice.cost = parseFloat(item.cost_price);
      this.subOrderPrice.freight = parseFloat(item.freight_price);
      this.subOrderPrice.difference = parseFloat(item.difference_price);
    },
    submitPrice() {
      this.is_set_price_show = false;
      let self = this;
      let json = {
        id: this.order_id,
        price: this.subOrderPrice,
      };
      self.$api[self.apiName].setOrderPrice(json).then((response) => {
        if (response.code == 1) {
          self.onLoad();
        }
      });
    },
    setOrderLogistics(order_id) {
      //修改快递单号
      this.is_set_price_show = true;
      this.order_id = order_id;
    },
    submitUpdate() {
      let item_number_temp = [];
      let item_id_temp = [];
      this.goodsData.forEach((item) => {
        if (item.select) {
          item_id_temp.push(item.id);
          item_number_temp.push(item.now_send_number);
        }
      });
      this.item_id = item_id_temp;
      this.item_number = item_number_temp;
    },
    searchOrder() {
      this.buttonType = 0;
      this.queryForm.status = 0;
      this.getPageData(true);
    },
    // 确认收款
    setParastatus(id, item) {
      this.parastatus = true;
      this.order_id = id;
      this.actual_price =
        parseFloat(item.order_total) +
        parseFloat(item.difference_price) +
        parseFloat(item.freight_price);
    },

    // 确认收货
    confirmTake(id) {
      let self = this;
      this.$confirm("确定要确认收货吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          self.$api[self.apiName].confirmTake(id).then((response) => {
            if (response.code == 1) {
              self.onLoad();
            }
          });
        })
        .catch(() => { });
    },
    // 物流方式
    logType(val) {
      if (val == 1) {
        this.is_logType_show = true;
      } else {
        this.is_logType_show = false;
      }
    },
    // 查看物流
    showLogistics(id) {
      let self = this;
      var json = { id: id };
      self.$api[self.apiName].logisticsLog(json).then((response) => {
        if (response.code == 1) {
          self.logistics_log = response.data;
          self.is_logistics_log_show = true;
        }
      });
    },
    getLogisticsTraces(id) {
      let self = this;
      var json = {
        logistics_id: id,
      };
      self.$api[self.apiName].logisticsLog(json).then((response) => {
        if (response.code == 1) {
          self.logistics_log.traces = response.data.traces;
        }
      });
    },
    // 设置物流信息
    setLogistics(id) {
      this.getItemsInfo(id);
      this.objForm.id = id;
      this.is_logistics_show = true;
    },
    submitLogistics() {
      this.submitUpdate();
      let form = {
        order_id: this.objForm.id,
        item_id: this.item_id.join(","),
        item_number: this.item_number.join(","),
        code: this.code,
        number: this.number,
        remark: this.remark,
      };
      let self = this;
      self.$api[self.apiName].saveLogistics(form).then((response) => {
        if (response.code == 1) {
          self.is_logistics_show = false;
          self.item_id = [];
          self.item_number = [];
          self.code = "";
          self.number = "";
          self.remark = "";
          self.getPageData();
          // self.getItemsInfo();
        }
      });
    },
    // 实际收款金额
    submitPara() {
      let self = this;
      let form = {
        order_id: this.order_id,
        actual_price: this.actual_price,
      };
      self.$api[self.apiName].setPayOrder(form).then((response) => {
        if (response.code == 1) {
          this.parastatus = false;
          this.$message({
            message: response.msg,
            type: "success",
          });
          self.getPageData();
        }
      });
    },
    getLogisticsAll() {
      let self = this;
      if (self.logistics.length <= 0) {
        self.$api[self.apiName].logisticsAll().then((response) => {
          if (response.code == 1) {
            self.logistics = response.data;
          }
        });
      }
    },
    getItemsInfo(id) {
      let self = this;
      var josn = {
        id: id,
        type: "system",
      };
      self.goodsData = [];
      self.$api[self.apiName].getItemsInfo(josn).then((response) => {
        if (response.code == 1) {
          self.goodsData = response.data;
        }
      });
    },
    afterGetInfo() {
      this.getLogisticsAll();
      this.getItemsInfo();
    },
    handleSelectionChange(e) {
      let self = this;
      if (self.goodsData) {
        self.goodsData.forEach((itemx, index) => {
          self.goodsData[index].select = false;
          if (e) {
            e.forEach((item) => {
              if (itemx.id == item.id) {
                self.goodsData[index].select = true;
              }
            });
          }
        });
      }
    },
    changeStatus(val) {
      this.buttonType = val;
      this.queryForm.status = val;
      this.getPageData();
    },
  },
  mounted() {
    this.queryForm.status = this.$route.query.status;
    if (this.$route.query.status) {
      this.buttonType = this.$route.query.status;
    }
    this.queryForm.status = this.buttonType;
  },
  created() {
    if (this.$route.params.id) {
      this.objForm.id = this.$route.params.id;
    }
    this.getLogisticsAll();
  },
};
</script>
<style lang="scss" scoped>
// .el-dialog__footer {
//   text-align: left;
// }
.goods-number {
  margin-left: 20px;
  margin-top: 15px;
}

.goods-title {
  overflow: hidden;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
  white-space: nowrap;
  width: 300px;
  display: block;
}

.logistics-number {
  margin-top: 20%;
}

.line {
  width: 100%;
  height: 1px;
  background-color: #eee;
}

.head-img {
  width: 100%;
  text-align: center;
}

.head-img .el-img {
  width: 48px;
  height: 48px;
  border-radius: 48px;
}

.nick_name {
  width: 100%;
  text-align: center;
}

.order {
  margin-top: 10px;
  border-top: 1px solid #ebeef5;
  border-bottom: 1px solid #ebeef5;

  .order-head {
    background: #f7f7f7;
    line-height: 35px;

    .order-sn {
      margin-left: 15px;
    }
  }

  .order_main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-overflow: ellipsis;
    align-content: center;
    white-space: normal;
    word-break: break-all;
    line-height: 23px;
  }
}

.goods_title_p {
  display: flex;
  line-height: 30px;

  .goods_title {
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
    white-space: nowrap;
    width: 200px;
    display: block;
  }

  .goods_names {
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
    white-space: nowrap;
    width: 150px;
    display: block;
  }
}

.el-button {
  margin-bottom: 10px;
  margin-right: 10px;
  margin-left: 0;
}

.text {
  color: #409eff;
  background: #ecf5ff;
}

.info {
  color: #67c23a;
  background: #f0f9eb;
}

.order-price {
  .label {
    display: inline-block;
    width: 115px;
  }

  .price {
    display: inline-block;
    width: 100px;
    color: #999;
  }
}
</style>